package com.finger.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

public class Cart {

    private List<CartItem> items;
    private Integer countNum;
    private Integer countType;
    private BigDecimal totalAmount;
    private BigDecimal reduct = new BigDecimal("0");

    public Cart() {
    }

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int i = 0;
        for (CartItem item : this.items) {
            i += item.getCount();
        }
        this.countNum = i;
        return this.countNum;
    }

    public Integer getCountType() {
        int i = 0;
        for (CartItem item : this.items) {
            i++;
        }
        this.countType = i;
        return this.countType;

    }

    public BigDecimal getTotalAmount() {
        BigDecimal bigDecimal = new BigDecimal("0");
        for (CartItem item : this.items) {
            // 如果当前元素选中，添加金额
            if (item.getCheck()) {
                bigDecimal = bigDecimal.add(item.getTotalPrice());
            }
        }
        this.totalAmount = bigDecimal;
        return this.totalAmount;
    }

    public BigDecimal getReduct() {
        return reduct;
    }

    public void setReduct(BigDecimal reduct) {
        this.reduct = reduct;
    }

}
